package com.hrzyit.whistle.cases.presenter

import android.util.Log
import com.hrzyit.base.ext.execute
import com.hrzyit.base.presenter.BasePresenter
import com.hrzyit.base.rx.BaseObserver
import com.hrzyit.whistle.cases.common.CaseConstant
import com.hrzyit.whistle.cases.data.bean.CategoryEntity
import com.hrzyit.whistle.cases.data.bean.SysDictEntity
import com.hrzyit.whistle.cases.presenter.view.CaseTypeView
import com.hrzyit.whistle.cases.service.ICaseTypeService
//import rx.Observable
import io.reactivex.Observable
import javax.inject.Inject

/**
 * 案件类型选择器 Presenter
 * @author YangWei
 * @date 2019/4/1
 */
class CaseTypePresenter @Inject constructor() : BasePresenter<CaseTypeView>() {

    @Inject
    lateinit var caseTypeService: ICaseTypeService

    /**
     * 获取案件类型列表：问题类型(事件、部件、环境)
     * @author YangWei
     * @date 2019/3/25
     * @param parentId      字典项父id
     * @param id            字典项id
     * @return List<SysDictEntity> 案件类型：问题类型
     */
    fun getCaseQuestionType() {

        if (!checkNetWork()) {
            return
        }

        // 显示进度框 ??
        mView.showLoading()

        val parentId = CaseConstant.CASE_QUESTION_TYPE_ID
        val id:Int? = null

        caseTypeService.getCaseQuestionTypeList(parentId, id)
            .execute(object : BaseObserver<MutableList<SysDictEntity>>(mView) {

                override fun onNext(t: MutableList<SysDictEntity>){
                    mView.onGetCaseQuestionTypeResult(t)
                }

            }, lifecycleProvider)
    }

    /**
     * 获取案件类型列表：大类
     * @author YangWei
     * @date 2019/3/25
     * @param parentId      案件类型父id
     * @return List<CategoryEntity> 案件类型：大类
     */
    fun getOneCategory(parentId: Long) {

        if (!checkNetWork()) {
            return
        }

        // 显示进度框 ??
        mView.showLoading()

        caseTypeService.getCategoryList(parentId, 1)
            .execute(object : BaseObserver<MutableList<CategoryEntity>>(mView) {

                override fun onNext(t: MutableList<CategoryEntity>) = mView.onGetOneCategoryResult(t)

            }, lifecycleProvider)
    }

    /**
     * 获取案件类型列表：小类
     * @author YangWei
     * @date 2019/3/25
     * @param parentId      案件类型父id
     * @return List<CategoryEntity> 案件类型：小类
     */
    fun getSecondCategory(parentId: Long) {

        if (!checkNetWork()) {
            return
        }

        // 显示进度框
        mView.showLoading()

        caseTypeService.getCategoryList(parentId, 2)
            .execute(object : BaseObserver<MutableList<CategoryEntity>>(mView) {

                override fun onNext(t: MutableList<CategoryEntity>) = mView.onGetSecondCategoryResult(t)

            }, lifecycleProvider)
    }


}